package com.gkey.demo.redis;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

@Controller
@RequestMapping("/redis")
public class RedisController {
	
	@Resource
	protected JedisPool jedisPool;
	
	int i = 1;
	
	@RequestMapping
    public String index(HttpServletRequest request, HttpServletResponse response, Model model) {
		Jedis jedis = jedisPool.getResource();
		String key = jedis.get("key");
		jedis.close();
		//jedisPool.close();
		i++;
		model.addAttribute("key", key);
		model.addAttribute("i", i);
        return "redis";
    }    
	

}
